<?php
header("Content-type: text/html;charset=utf-8");
//$file_name = 'D:/测试文件.docx';
$file_name = $_GET['file'];
//$file_path = iconv("utf-8","gbk//IGNORE",$file_name);
$file_path = $file_name;
if (!file_exists($file_path)){
    echo "文件不存在";
    exit();
}
//下载文件必须要将文件先打开。写入内存
$fp = fopen($file_path,"r+") or die('打开文件错误');
//返回的文件流
Header("Content-type:application/octet-stream");
//按照字节格式返回
Header("Accept-Ranges:bytes");
//返回文件大小
Header("Accept-Length:".filesize($file_path));
//弹出客户端对话框，对应的文件名
Header("Content-Disposition:attachment;filename=".$file_name);
//防止服务器瞬间压力增大，分段读取
$buffer = 1024;
while(!feof($fp)){
    $file_data = fread($fp,$buffer);
    echo $file_data;
}
fclose($fp);
?>